﻿/*
 * Created by SharpDevelop.
 * User: CrOnO
 * Date: 20/10/2011
 * Time: 04:35 a.m.
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Data.SqlClient;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using Business_Entity;

namespace DAOFactory
{
	/// <summary>
	/// Description of DAOTipoDocumento.
	/// </summary>
	public class DAOTipoDocumento
	{
		public DAOTipoDocumento()
		{
		}
		/*
        public static List<BETipoDocumento> findTipoDocumento()
        {
            List<BETipoDocumento> lista = new List<BETipoDocumento>();

            //ConnectionManager.closeConnection();
            SqlCommand cmd = new SqlCommand("VENTAS_OBTENER_TIPODOCUMENTO2_R", ConnectionManager.getConnection());
            cmd.CommandType = CommandType.StoredProcedure;

            SqlDataReader reader = cmd.ExecuteReader();

            if (reader.HasRows)
            {

                while (reader.Read())
                {
                    String id = reader[0].ToString();
                    String descripcion = reader[1].ToString();
                    lista.Add(new BETipoDocumento(int.Parse(id), descripcion));
                    //System.Windows.Forms.MessageBox.Show(id+" "+descripcion);
                }
                reader.Close();
                return lista;
            }
            else
            {
                reader.Close();
                System.Windows.Forms.MessageBox.Show("Error al cargar Area de la BD", "Aviso");
                return null;
            }
        }
		*/
		public List<BETipoDocumento> completarTipoDocumento2()
		{
			SqlDataReader amd = null;
			List<BETipoDocumento> lista = new List<BETipoDocumento>();
			
			try{
				SqlCommand cmd = new SqlCommand("RRHH_OBTENER_TIPO_DOC_L", ConnectionManager.getConnection());
				cmd.CommandType = CommandType.StoredProcedure;
					
				amd = cmd.ExecuteReader();				
				
				if (amd.HasRows) 
				{
					lista.Add(new BETipoDocumento(-1,"<Seleccionar>"));
					
					while(amd.Read())
					{
						BETipoDocumento tipoDoc = new BETipoDocumento();
						tipoDoc.IdTipoDoc = Int32.Parse(amd[0].ToString());
						tipoDoc.Descripcion = amd[1].ToString();
						lista.Add(tipoDoc);
					}				
				}
			}
			catch(SqlException e){
//				System.Windows.Forms.MessageBox.Show(e.ToString(),"Error");
			}
			
			if(amd != null)
				amd.Close();
			return lista;
		}
		
		public List<BETipoDocumento> completarTipoDocumento()
		{
			try{
				SqlCommand cmd = new SqlCommand("RRHH_OBTENER_TIPO_DOC_L", ConnectionManager.getConnection());
				cmd.CommandType = CommandType.StoredProcedure;
					
				SqlDataReader amd = cmd.ExecuteReader();
				List<BETipoDocumento> lista = new List<BETipoDocumento>();
				
				if (amd.HasRows) 
				{
					lista.Add(new BETipoDocumento(-1,"<Seleccionar>"));
					
					while(amd.Read())
					{
						BETipoDocumento tipoDoc = new BETipoDocumento();
						
						try
						{
							tipoDoc.IdTipoDoc = Int32.Parse(amd[0].ToString());
							tipoDoc.Descripcion = amd[1].ToString();
							lista.Add(tipoDoc);
						}
						catch
						{
							System.Windows.Forms.MessageBox.Show("Error al obtener Tipo de Documento","Error");
							amd.Close();
							return null;
						}
					}
					amd.Close();
					
					return lista;
				}
				else
				{
					amd.Close();				
					return null;
				}
			}
			catch
			{
				return null;
			}
		}
		
	}
}
